<template>
  <div>
    <el-form class="input-form"
      label-position="right"
      label-width="120px"
      ref="editForm"
      :rules="propRules"
      :disabled="propReadonly"
      :model="form"
    >
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="品名" prop="matrName">
            <el-input v-model="form.matrName" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="品规" prop="matrSpec">
            <el-input v-model="form.matrSpec" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="批次" prop="lot">
            <el-input v-model="form.lot" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="供应商" prop="supplierName">
            <el-input v-model="form.supplierName" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="效期" prop="expDate">
            <el-date-picker v-model="form.expDate" type="date" :format="dates.defaultDatePattern"  :picker-options="dates.pickerOptions.date" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="生产日期" prop="mfgDate">
            <el-date-picker v-model="form.mfgDate" type="date" :format="dates.defaultDatePattern"  :picker-options="dates.pickerOptions.date" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="包装单位" prop="packageUnit">
            <el-input v-model="form.packageUnit" :disabled="true"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="包装数量" prop="packageQty">
            <el-input-number v-model="form.packageQty" :disabled="true" label="包装数量"></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="金额" prop="amount">
            <el-input v-model="form.amount" :disabled="true"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="单品数量" prop="skuQty">
            <el-input v-model="form.skuQty" :disabled="true"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="单品价格" prop="skuPrice">
            <el-input v-model="form.skuPrice" :disabled="true"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="sn" prop="sn">
            <el-input v-model="form.sn" :disabled="true"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="rfid" prop="rfid">
            <el-input v-model="form.rfid" :disabled="true"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="udi" prop="udi">
            <el-input v-model="form.udi" :disabled="true"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="寄售" prop="flagConsignment">
            <el-input v-model="flagConsignment" :disabled="true"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="一物一码" prop="flagOmoc">
            <el-input v-model="flagOmoc" :disabled="true"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input type="textarea" v-model="form.remark" :autosize="{ minRows: 2, maxRows: 4}"/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>

export default {
  data() {
    return {
      form: {},
      viewData: {},
      flagConsignment: '是',
      flagOmoc: '是'
    }
  },
  methods: {

  },
  created() {
    let that = this
    this.$emit('event-register', {
      validate: (callback) => {
        this.$refs.editForm.validate(callback)
      },
      beforeSave: () => {
        this.$emit('data-callback', this.form)
        return true
      },
      afterMove: (formData, initData) => {
        this.form = global.utils.jsonClone(formData)
        this.$set(this.$data, 'flagConsignment', this.form.flagConsignment ? '是' : '否')
        this.$set(this.$data, 'flagOmoc', this.form.flagOmoc ? '是' : '否')
        this.$set(this.form, 'packageRate', this.form.packageQty == 0 ? 0 : this.form.skuQty / this.form.packageQty)
        // 设置switch 元素默认值
      },
      afterSave: () => {
        that.propParentPage.$emit('refresh-row')
      },
      beforeDelete: () => {
        return true
      },
      afterDelete: () => {
      },
      beforeFlow: (flowButtonKey) => {
        return true
      },
      afterFlow: (flowButtonKey) => {
      },
      beforeClose: () => {
        return true
      }
    })
  },
  props: {
    propParent: Object,
    propInitData: Object,
    propPrimaryKey: String,
    propDictionaries: Object,
    propCurrentRow: Object,
    propViewFormData: Object,
    propReadonly: Boolean,
    propStatus: String,
    propRules: Object,
    propParentPage: Object
  },
  watch: {
    //包装数量发生变化时，重新计算单品数量和总价
    'form.packageQty': {
      handler(newVal) {
        this.form.skuQty = this.form.packageRate * newVal
        this.form.amount = this.form.skuPrice * this.form.skuQty
      },
      deep: true
    },
    'form.skuQty': {
      handler(newVal) {
        if (isNaN(newVal)) {
          this.form.skuQty = ''
        }
      },
      deep: true
    },
    'form.amount': {
      handler(newVal) {
        if (isNaN(newVal)) {
          this.form.amount = ''
        }
      },
      deep: true
    }
  },
  components: {
  },
  computed: {
  }
}
</script>

<style lang="scss" scoped>
  .container {
    width: 100%;
    height: 100%;
  }
</style>
